import { executeSql } from "../util/db.js";

//根据id查询指定文章类别
export const selectCategoryById = function (cid) {
    let sql = "select * from categories where id=?"
    return executeSql(sql, [cid])
}
//删除分类
export const deleteCategoryById = function (cid) {
    let sql = "delete from categories where id=?"
    return executeSql(sql, [cid])
}

//新增文章类别
export const addNewCategory = function (name, slug) {
    let sql = "insert into categories values( null,?,?,0 )";
    return executeSql(sql, [name, slug])
}

//更新分类信息
export const updateCategory = function (name, slug, id) {
    let sql = "update categories set name=?,slug=? where id=?";
    return executeSql(sql, [name, slug, id])
}

//根据分类名称查询分类
export const selectCategoryByName = function (name) {
    let sql = "select * from categories where name=?";
    return executeSql(sql, [name])
}
//根据别名查询分类
export const selectCategoryBySlug = function (slug) {
    let sql = "select * from categories where slug=?";
    return executeSql(sql, [slug])
}

//所有文章类别
export const selectAllCategory = function () {
    let sql = "select id,name,slug from categories";
    return executeSql(sql)
}





